/**
 * 命令模式：结构上类似于适配器，主要是将方法调用封装成对象，以达到解耦的目的
 */
public class CommandPattern {
    public static void main(String[] args) {
        Light light = new Light();
        Command lightOnCommand = new LightOnCommand(light);

        RemoteControl remoteControl = new RemoteControl();
        remoteControl.setCommand(lightOnCommand);
        remoteControl.commandTodo();
    }
}
// 命令接口
interface Command {
    void execute();
}
// 具体命令类
class LightOnCommand implements Command {
    Light light;

    public LightOnCommand(Light light) {
        this.light = light;
    }
    @Override
    public void execute() {
        light.on();
    }
}
// 接收者类
class Light {

    public void on() {
        System.out.println("Light is on");
    }
}
// 调用者类
class RemoteControl {
    private Command command;

    public void setCommand(Command command) {
        this.command = command;
    }
    public void commandTodo() {
        command.execute();
    }
}
